package beans;

import java.io.Serializable;
import java.util.*;
import toolbox.*;

import java.sql.*;

public class VmTemplateBean implements Serializable {
	private static final long serialVersionUID = 1L;
	private int ID;
	private String OS;
	private int DiskSize;
	private int RamSize;
	private int CPU;
	public int getID() {
		return ID;
	}
	public void setID(int id) {
		ID = id;
	}
	public String getOS() {
		return OS;
	}
	public void setOS(String os) {
		OS = os;
	}
	public int getDiskSize() {
		return DiskSize;
	}
	public void setDiskSize(int diskSize) {
		DiskSize = diskSize;
	}
	public int getRamSize() {
		return RamSize;
	}
	public void setRamSize(int ramSize) {
		RamSize = ramSize;
	}
	public int getCPU() {
		return CPU;
	}
	public void setCPU(int cpu) {
		CPU = cpu;
	}
	public ArrayList<String> getAllTemplates()
	{
		Connection con = DBconne.getConnection();
		String sql = "select * from VMTemplate";
		ResultSet rs = null;
		Statement stmt = null;
		ArrayList<String> list = new ArrayList<String>();
		try{
			stmt = con.createStatement();
			rs = stmt.executeQuery(sql);
			if(rs == null) System.out.println("result is null!");
			while(rs.next()){
				int numOfCore = Integer.valueOf(rs.getString("CPU"));
				String str = null;
				if(numOfCore>1) str = "cores CPU/";
				else str = "core CPU/";
				
				list.add(rs.getString("ID")+" "+rs.getString("OS")+"( "+rs.getString("CPU")
						+str+rs.getString("RamSize")+"G RAM/"+rs.getString("DiskSize")
						+"G DiskSpace )");
			}
		} catch (SQLException e) { 
			System.out.println("SQLException in VmTemplate in getAllTemplete");
		} finally{
			try{
				if(stmt == null) {
					System.out.println("pstmt is null!Wrong here!");
				} else stmt.close();
				DBconne.closeConnection();
			}catch (SQLException e){}
		}
		return list;
	}
}
